package com.example.hasee.zhcd.Activities.ChuanWu;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hasee.zhcd.Adapters.NearPointListAdapter;
import com.example.hasee.zhcd.Base.BaseActivity;
import com.example.hasee.zhcd.Bean.EventMsg;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.ProgressDialogUtils;
import com.example.hasee.zhcd.View.NoScrollListView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by hasee on 2018/5/31.
 */

public class NearPointActivity extends BaseActivity {
    private String strShipCode;
    private String strSYN;
    private String strWTF;
    private ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    private NearPointListAdapter adapter;
    private TextView title;
    private ImageView back;
    private ImageView home;
    private NoScrollListView content_list;
    private TextView add_title;
    private TextView add_content;

    @Override
    public int contentViewId() {
        return R.layout.activity_near_point;
    }

    @Override
    public void set() {
        title.setText("靠泊重点");
        back.setOnClickListener(this);
        home.setVisibility(View.INVISIBLE);
        getPoint();
    }

    @Override
    public void init() {
        strShipCode = getIntent().getExtras().getString("strShipCode");
        strSYN = getIntent().getExtras().getString("strSYN");
        strWTF = getIntent().getExtras().getString("strWTF");
        back = (ImageView) findViewById(R.id.back);
        home = (ImageView) findViewById(R.id.home);
        title = (TextView) findViewById(R.id.centertitle);
        content_list = (NoScrollListView) findViewById(R.id.content_list);
        add_title = (TextView) findViewById(R.id.add_title);
        add_content = (TextView) findViewById(R.id.add_content);
    }

    @Override
    public void getEventData(EventMsg msg) {
        switch (msg.getAction()) {
            case "Fail":
                ProgressDialogUtils.closeProgressDialog();
                Toast.makeText(NearPointActivity.this, "操作失败，请检查网络！", Toast.LENGTH_LONG).show();
                break;
            case "ZHCW_kbcb_zd":
                ProgressDialogUtils.closeProgressDialog();
                //ZHCW_kbcb_zd: {"data":[{"fnote":"新晨富 未签合同，请通知主管：李真　联系电话：13383358968"}],"rspcode": 0,"rspmessage":""}
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    String rspmessage = json.getString("rspmessage");
                    if ("0".equals(rspcode)) {
                        JSONArray data = json.getJSONArray("data");
                        for (int i = 0; i < data.length(); i++) {
                            HashMap<String, String> map = new HashMap<String, String>();
                            map.put("fnote", data.getJSONObject(i).getString("fnote"));
                            list.add(map);
                        }
                        adapter = new NearPointListAdapter(NearPointActivity.this, list);
                        content_list.setAdapter(adapter);
                        if (rspmessage.length() != 0) {
                            add_content.setText(rspmessage);
                        } else {
                            add_content.setVisibility(View.GONE);
                            add_title.setVisibility(View.GONE);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
        }
    }

    private void getPoint() {
        ProgressDialogUtils.createProgressDialog(NearPointActivity.this, "正在获取数据...");
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strShipCode", strShipCode);
        map.put("strSYN", strSYN);
        map.put("strWTF", strWTF);
        httpUtils.get("ZHCW_kbcb_zd", map, "ZHCW_kbcb_zd");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }
}
